package com.bjpowernode.controller;

import com.bjpowernode.entity.TTran;
import com.bjpowernode.query.TranQuery;
import com.bjpowernode.result.Result;
import com.bjpowernode.service.TranService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
public class TranController {


    @Resource
    private TranService tranService;

    @PostMapping("/api/tran")
    public Result createTran(@RequestBody TranQuery tranQuery) {
        int num = tranService.createTran(tranQuery);

        return num > 0 ? Result.OK() : Result.FAIL();
    }


    @GetMapping("api/trans")
    public Result getTranByPage(Integer current) {
        PageInfo<TTran> pageInfo =  tranService.getTranByPage(current);
        return Result.OK(pageInfo);
    }


    @GetMapping("api/tran/{id}")
    public Result getTranById(@PathVariable Integer id) {
        TTran tran = tranService.getTranById(id);
        return Result.OK(tran);
    }
}
